package cn.itcast.ssm.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
* Created By lijiliang on 2018年7月13日 下午4:36:57
*/
public class HandlerInterceptor2 implements HandlerInterceptor {

	//进入Handler方法之前执行
	//用于身份认证，身份授权
	//比如身份认证
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		// TODO Auto-generated method stub
		System.out.println("HandlerInterceptor2...preHandle");
		return true;//表示拦截，不能向下执行
	}

	//进入Handler方法之后，返回modelAndView之前执行
	//将公用的模型数据传到视图
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub
		System.out.println("HandlerInterceptor2...postHandle");
	}

	//执行Handler完成执行方法之后
	//统一的异常处理，统一的日志处理
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
			Exception ex)
			throws Exception {
		// TODO Auto-generated method stub
		System.out.println("HandlerInterceptor2...afterCompletion");
	}

}
